package com.mlnx.service.base.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mlnx.common.utils.MyLog;
import org.shan.spring.cache.CacheChannel;
import org.shan.spring.cache.CacheObject;
import org.shan.spring.mybatis.service.BaseMybatisService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by amanda.shan on 2019/7/15.
 */

public class BaseService<M extends BaseMapper<T>, T> extends BaseMybatisService<M, T> {

    protected MyLog log = MyLog.getLog(getClass());

    @Autowired
    protected CacheChannel cacheChannel;

    protected void evict(String region, String key) {
        cacheChannel.evict(region, key);
    }

    public <W> W getCache(String region, String key, Class<W> tClass) {
        CacheObject cacheObject = cacheChannel.get(region, key);
        return cacheObject.getObject(tClass);
    }


    public void setCache(String region, String key, Object value) {
        cacheChannel.set(region, key, value);
    }

}
